#!/usr/bin/python3.5

# -*- coding: utf-8 -*-


def binary_search(arr,target):
    k=0
    l=0
    r = len(arr)
    if arr[l]==target or arr[r-1]==target:
          return True
    while r>l:
        mid = (r+l)//2
        k+=1
        if arr[mid]==target:
            if mid>0 and arr[mid-1]==target:
                r = mid
            else:
                print(mid)
                return True


        elif arr[mid]>target:
            r = mid
        else:
            l = mid+1
    return False



if __name__ == "__main__":
    n = 100
    a = [1,2,2,3,3,3,3,3,4,5,6,7,8]
    target = 2
    print(binary_search(a,target))
